package com.johnsoft.pph.gui;

import java.awt.GridBagLayout;
import java.util.List;
import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.JFrame;

/**
 * Basic Class to hold Interface Data and to register it to the JFrame Container
 * @author Johnnei
 *
 */
public abstract class IGui {
	
	private List<JComponent> component;
	private List<int[]> location;
	
	public IGui()
	{
		component = new ArrayList<JComponent>();
		location = new ArrayList<int[]>();
	}
	
	public void add(JComponent comp, int x, int y, int width)
	{
		component.add(comp);
		location.add(new int[] { x, y, width });
	}
	
	abstract JFrame installFrame(JFrame frame);
	abstract JFrame uninstallFrame(JFrame frame);
	
	/**
	 * Reverts registerFrame(JFrame)
	 * @param frame
	 * @return a cleaned JFrame
	 */
	public JFrame cleanFrame(JFrame frame)
	{
		frame = uninstallFrame(frame);
		//frame.revalidate();
		frame.repaint();
		return frame;
	}
	
	/**
	 * Installs all components from this GUI to the given JFrame
	 * @param frame The JFrame to place the components on
	 * @return frame with installed components
	 */
	public JFrame registerFrame(JFrame frame)
	{
		frame.setLayout(new GridBagLayout());
		frame = installFrame(frame);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		//frame.revalidate();
		frame.repaint();
		return frame;
	}

}
